package gases.as3.testing
{
	import flash.display.DisplayObject;
	import flash.display.Loader;
	import flash.display.LoaderInfo;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.net.URLRequest;
	import flash.utils.setTimeout;
	
	import gases.as3.librarys.compnents.events.TreeEvent;
	import gases.as3.librarys.compnents.resource.MacroResourceManagaers;
	import gases.as3.librarys.compnents.skin.SkinStylesMangaer;
	import gases.as3.librarys.compnents.skin.SkinTransform;
	import gases.as3.librarys.compnents.skin.data.BaseSkin;
	import gases.as3.librarys.compnents.skin.transform.TransformXML;
	import gases.as3.librarys.compnents.ui.control.Tree;
	
	public class TestingTree extends Sprite
	{
		public function TestingTree()
		{
			super();
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			var loader:Loader = new Loader();
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
			loader.load(new URLRequest("assets/treeSkin.swf"));
		}
		private function onComplete(e:Event):void
		{
			var swf:DisplayObject = LoaderInfo(e.target).content as DisplayObject;
			MacroResourceManagaers.instance.UIResManager.setUISkinSwf(swf);
			var transform:SkinTransform = new SkinTransform();
			transform.setConfigTransform(new TransformXML());
			transform.resloveSkinConfig(treeSkinXML);
			
			var treeSkin:BaseSkin = SkinStylesMangaer.instance.getSkinData("tree_image") as BaseSkin;
			_tree = new Tree(); 
			_tree.x =100;
			_tree.treeWidth = 180;
			_tree.skin = treeSkin;
			_tree.dataProvider = xml;
			_tree.addEventListener(TreeEvent.CHANGE_HEIGHT,changeHeight);
			_tree.addEventListener(TreeEvent.CLICK_NODE,clickNode);
			this.addChild(_tree);
			
			setTimeout(test,5000);
		}
		
		private function test():void
		{
			_tree.dataProvider = xml_test;
		}
		private function changeHeight(e:TreeEvent):void
		{
			trace(e.data);
		}
		
		private function clickNode(e:TreeEvent):void
		{
			trace(e.data);
		}
		
		private var _tree:Tree;
		private var bmd:Object ;
		
		private var treeSkinXML:XML = <root>
											<skin type="tree" scale9_top="5" scale9_left="5" scale9_right="5" scale9_bottom="5" skinname="tree_image" width="60" height="20">
												<styles stylesName="open_icon" resName="open"/>
												<styles stylesName="close_icon" resName="close"/>
												<styles stylesName="leaf_icon" resName="leaf"/>
											</skin>
									</root>;
		
		public static var xml:XML = <root>
			                              <node label="first node" id="first">
											<node label="first leaf" id="1_1" data="show first leaf"/>
											<node label="second leaf"id="1_2" data="show second leaf"/>
										 </node>
										 <node label="second node" id="second">
											<node label="first component" id="2_1" data="show first component">
												<node label="second first leaf" id="2_1_1" data="second show first leaf"/>
											</node>
											<node label="second component"id="2_2" data="show second component">
												<node label="second second leaf" id="2_2_1" data="second show second leaf"/>
												<node label="second second leaf" id="2_2_2" data="second show second leaf"/>
											</node>
										 </node>
								     </root>;
		public static var xml_test:XML = <root>
			                              <node label="first node" id="first">
											<node label="first leaf" id="1_1" data="show first leaf"/>
											<node label="second leaf"id="1_2" data="show second leaf"/>
										 </node>
			                              <node label="first node" id="first">
											<node label="first leaf" id="1_1" data="show first leaf"/>
											<node label="second leaf"id="1_2" data="show second leaf"/>
										 </node>
										 <node label="second node" id="second">
											<node label="first component" id="2_1" data="show first component">
												<node label="second first leaf" id="2_1_1" data="second show first leaf"/>
											</node>
											<node label="second component"id="2_2" data="show second component">
												<node label="second second leaf" id="2_2_1" data="second show second leaf"/>
												<node label="second second leaf" id="2_2_2" data="second show second leaf"/>
											</node>
										 </node>
								     </root>;
		
	}
}